# Maintainer: Ryuta Suzuki <oroppas@gmail.com>

_realname=prompt_toolkit
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.0.10
pkgrel=1
pkgdesc="Library for building powerful interactive command lines in Python (mingw-w64)"
url="https://github.com/jonathanslenders/python-prompt-toolkit"
arch=('any')
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-pygments"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-six"
             "${MINGW_PACKAGE_PREFIX}-python2-wcwidth"
             "${MINGW_PACKAGE_PREFIX}-python3-pygments"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-six"
             "${MINGW_PACKAGE_PREFIX}-python3-wcwidth")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytest"
              "${MINGW_PACKAGE_PREFIX}-python3-pytest")
source=(python-prompt-toolkit-${pkgver}.tar.gz::https://github.com/jonathanslenders/python-prompt-toolkit/archive/${pkgver}.tar.gz)
sha256sums=('4877317746abf9040459fc6326a123bcf8e68ffa2c9c3bb901102ad7bc3016d3')

prepare() {
  cd "${srcdir}"
  for builddir in python{2,3}-build-${CARCH}; do
    rm -rf ${builddir} | true
    cp -r "python-prompt-toolkit-${pkgver}" "${builddir}"
  done
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

build() {
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {
  msg "Python 2 build for ${CARCH}"
  cd "${srcdir}/python2-build-${CARCH}"
  ${MINGW_PREFIX}/bin/py.test2 || warning "Tests failed"

  msg "Python 3 build for ${CARCH}"
  cd "${srcdir}/python3-build-${CARCH}"
  ${MINGW_PREFIX}/bin/py.test || warning "Tests failed"
}

package_python2-prompt_toolkit() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-pygments"
           "${MINGW_PACKAGE_PREFIX}-python2-six"
           "${MINGW_PACKAGE_PREFIX}-python2-wcwidth")
  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --root=${pkgdir} \
   --prefix=${MINGW_PREFIX} --optimize=1 --skip-build
  install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE
}

package_python3-prompt_toolkit() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-pygments"
           "${MINGW_PACKAGE_PREFIX}-python3-six"
           "${MINGW_PACKAGE_PREFIX}-python3-wcwidth")
  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --root=${pkgdir} \
   --prefix=${MINGW_PREFIX} --optimize=1 --skip-build
  install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE
}

package_mingw-w64-i686-python3-prompt_toolkit() {
  package_python3-prompt_toolkit
}

package_mingw-w64-x86_64-python3-prompt_toolkit() {
  package_python3-prompt_toolkit
}

package_mingw-w64-i686-python2-prompt_toolkit() {
  package_python2-prompt_toolkit
}

package_mingw-w64-x86_64-python2-prompt_toolkit() {
  package_python2-prompt_toolkit
}

